package s2;

import java.util.List;

import s2.model.Category;
import s2.model.Offer;
import s2.repo.Repository;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

public class OfferController extends ActionSupport implements ModelDriven<Offer> {
	private static final long serialVersionUID = 1L;
	private Offer offer;

	public OfferController() {}

	public List<Category> getCategoriesOptions() {
		return Repository.getInstance().listAllCategories();
	}

	public String execute() throws Exception {
		return create();
	}

	public String create() {
		this.offer = new Offer();
		addActionMessage("New offer created.");
		return INPUT;
	}

	public String save() {
		addActionMessage("Offer saved.");
		return SUCCESS;
	}

	public Offer getModel() {
		if (offer == null) offer = new Offer();
		return offer;
	}
}
